﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eShop.Utility;
using eShop.Business;
using eShop.Model;

public partial class widget_products_list : BaseWidget
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            switch (ListType)
            {
                case ProductListType.Featured:
                    ShowProductListByFeatured();
                    break;
                case ProductListType.Category:
                    ShowProductListByCategory();
                    break;
                default :
                    this.Visible = false;
                    break;
            }
        }
    }

    private void ShowProductListByFeatured()
    {
        lHeading.Text = "Featured Products";
        productList.DataSource = ProductManager.FeaturedProducts(PageSize);
        productList.DataBind();
    }

    private void ShowProductListByCategory()
    {
        Category category = CategoryManager.GetCategoryById(CategoryId);
        lHeading.Text = category.CategoryName;
        productList.DataSource = ProductManager.ProductByCategory(CategoryId, "DisplayOrder", CurrentPageIndex, PageSize, DataState.Active);
        productList.DataBind();
        
        //ProductManager.ProductCountByCategory(CategoryId, DataState.Active);
    }

    public ProductListType ListType { get; set; }
    public int CurrentPageIndex { get; set; }
    public int PageSize { get; set; }


    public int CategoryId { get; set; }

    public enum ProductListType
    {
        Featured,
        Category,
        Manufacturer
    }
}